**# Preample 
clear all
cd "INSERTPATH" 								// Remember to update file directory ("INSERTPATH")

set scheme plotplain

**# App. B
use  "data_S1.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

gen support_inparty = . 
replace support_inparty = (feelings_dems/10) if pid < 0
replace support_inparty = (feelings_reps/10) if pid > 0
gen support_outparty = . 
replace support_outparty = (feelings_dems/10) if pid > 0
replace support_outparty = (feelings_reps/10) if pid < 0
gen aff_pol = (affective_polarization+10)/20
gen election = (pei-1)/4 

* In-party malpractice (table B1)
reg election i.condition if copartisan_D==1, rob
reg support_inparty i.condition if copartisan_D==1, rob 
reg vote_inparty i.condition if copartisan_D==1, rob 
reg support_outparty i.condition if copartisan_D==1, rob
reg vote_outparty i.condition if copartisan_D==1, rob 
reg vote_independent i.condition if copartisan_D==1, rob
reg aff_pol i.condition if copartisan_D==1, rob


* Out-party malpractice (table B2)
reg election i.condition if copartisan_D==0, rob
reg support_inparty i.condition if copartisan_D==0, rob 
reg vote_inparty i.condition if copartisan_D==0, rob 
reg support_outparty i.condition if copartisan_D==0, rob
reg vote_outparty i.condition if copartisan_D==0, rob 
reg vote_independent i.condition if copartisan_D==0, rob
reg aff_pol i.condition if copartisan_D==0, rob

* Alternative outcomes - in-party (table B3)
gen policy_inparty= . 
replace policy_inparty = ((dem_policy-1)/4) if pid < 0
replace policy_inparty = ((rep_policy-1)/4) if pid > 0
gen policy_outparty = . 
replace policy_outparty = ((dem_policy-1)/4) if pid > 0
replace policy_outparty = ((rep_policy-1)/4) if pid < 0

gen cheat_inparty= . 
replace cheat_inparty = ((dem_cheat-1)/4) if pid < 0
replace cheat_inparty = ((rep_cheat-1)/4) if pid > 0
gen cheat_outparty = . 
replace cheat_outparty = ((dem_cheat-1)/4) if pid > 0
replace cheat_outparty = ((rep_cheat-1)/4) if pid < 0

reg policy_inparty i.D if copartisan_D== 1 & pid != 0, rob
reg policy_outparty i.D if copartisan_D == 1 & pid != 0, rob
reg cheat_inparty i.D if copartisan_D== 1 & pid != 0, rob
reg cheat_outparty i.D if copartisan_D == 1 & pid != 0, rob

* Alternative outcomes - out-party (table B4)

reg policy_inparty i.D if copartisan_D== 0 & pid != 0, rob
reg policy_outparty i.D if copartisan_D == 0 & pid != 0, rob
reg cheat_inparty i.D if copartisan_D== 0 & pid != 0, rob
reg cheat_outparty i.D if copartisan_D == 0 & pid != 0, rob


**# App. D.1
use  "data_S1.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

* Balance
gen strong_pid = 0 
replace strong_pid = 1 if pid == 3 
replace strong_pid = 1 if pid == -3
gen mod_pid = 0 
replace mod_pid = 1 if pid == 2
replace mod_pid = 1 if pid == -2

gen female = 0 
replace female = 1 if gender == 2

gen rep = 0 
replace rep = 1 if party == 3

foreach var in female rep strong_pid mod_pid age {
	ttest `var',  by(D) unequal	
}


* Manipulation check: election legitimacy
gen election = (pei-1)/4 
reg election i.condition, rob 

* Treatment recall 
tab mc_pass			


**# App. E.1
use  "data_S1.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

* rescale DVs
gen support_inparty = . 
replace support_inparty = (feelings_dems/10) if pid < 0
replace support_inparty = (feelings_reps/10) if pid > 0
gen support_outparty = . 
replace support_outparty = (feelings_dems/10) if pid > 0
replace support_outparty = (feelings_reps/10) if pid < 0
gen aff_pol = (affective_polarization+10)/20


* In-party malpractice (table E1)
reg vote_outparty i.D if copartisan_D==1, rob
 reg support_inparty i.D if copartisan_D==1, rob
 reg support_outparty i.D if copartisan_D==1, rob
 reg aff_pol i.D if copartisan_D==1, rob



* Out-party malpractice (table E2)
reg vote_outparty i.D if copartisan_D==0, rob
reg support_inparty i.D if copartisan_D==0, rob
reg support_outparty i.D if copartisan_D==0, rob
reg aff_pol i.D if copartisan_D==0, rob



**# App. F.1
se  "data_S1.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

* rescale DVs
gen support_inparty = . 
replace support_inparty = (feelings_dems/10) if pid < 0
replace support_inparty = (feelings_reps/10) if pid > 0
gen support_outparty = . 
replace support_outparty = (feelings_dems/10) if pid > 0
replace support_outparty = (feelings_reps/10) if pid < 0
gen aff_pol = (affective_polarization+10)/20

reg election i.D, rob
reg support_inparty i.D, rob
reg vote_inparty i.D, rob
reg support_outparty i.D, rob
reg vote_outparty i.D, rob
reg aff_pol i.D, rob


**# App. G.1
use  "data_S1.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

* rescale DVs
gen support_inparty = . 
replace support_inparty = (feelings_dems/10) if pid < 0
replace support_inparty = (feelings_reps/10) if pid > 0
gen support_outparty = . 
replace support_outparty = (feelings_dems/10) if pid > 0
replace support_outparty = (feelings_reps/10) if pid < 0
gen aff_pol = (affective_polarization+10)/20

* In-party malpractice (table G1) 
reg election i.D if copartisan_D==1 & attention_3!=0, rob 
reg support_inparty i.D if copartisan_D==1 & attention_3!=0, rob 
reg vote_inparty i.D if copartisan_D==1 & attention_3!=0, rob  
reg support_outparty i.D if copartisan_D==1 & attention_3!=0, rob 
reg vote_outparty i.D if copartisan_D==1 & attention_3!=0, rob  
reg vote_independent i.D if copartisan_D==1 & attention_3!=0, rob 
reg aff_pol i.D if copartisan_D==1 & attention_3!=0, rob 

	

* Out-party malpractice (table G2)
reg election i.D if copartisan_D==0 & attention_3!=0, rob 
reg support_inparty i.D if copartisan_D==0 & attention_3!=0, rob 
reg vote_inparty i.D if copartisan_D==0 & attention_3!=0, rob  
reg support_outparty i.D if copartisan_D==0 & attention_3!=0, rob 
reg vote_outparty i.D if copartisan_D==0 & attention_3!=0, rob  
reg vote_independent i.D if copartisan_D==0 & attention_3!=0, rob 
reg aff_pol i.D if copartisan_D==0 & attention_3!=0, rob 


**# App. H.1
use  "data_S1.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above

* rescale DVs
gen support_inparty = . 
replace support_inparty = (feelings_dems/10) if pid < 0
replace support_inparty = (feelings_reps/10) if pid > 0
gen support_outparty = . 
replace support_outparty = (feelings_dems/10) if pid > 0
replace support_outparty = (feelings_reps/10) if pid < 0
gen aff_pol = (affective_polarization+10)/20


gen strong_moderate = 0 
replace strong_moderate = 1 if pid < -1
replace strong_moderate = 1 if pid > 1

* In-party malpractice (table H1)
reg election i.condition if copartisan_D==1 & strong_moderate == 1, rob
reg support_inparty i.condition if copartisan_D==1 & strong_moderate == 1, rob
reg vote_inparty i.condition if copartisan_D==1 & strong_moderate == 1, rob
reg support_outparty i.condition if copartisan_D==1 & strong_moderate == 1, rob
reg vote_outparty i.condition if copartisan_D==1 & strong_moderate == 1, rob
reg vote_independent i.condition if copartisan_D==1 & strong_moderate == 1, rob
reg aff_pol i.condition if copartisan_D==1 & strong_moderate == 1, rob

* Out-Party malpractice (table H2) 
reg election i.condition if copartisan_D==0 & strong_moderate == 1, rob
reg support_inparty i.condition if copartisan_D==0 & strong_moderate == 1, rob
reg vote_inparty i.condition if copartisan_D==0 & strong_moderate == 1, rob
reg support_outparty i.condition if copartisan_D==0 & strong_moderate == 1, rob
reg vote_outparty i.condition if copartisan_D==0 & strong_moderate == 1, rob
reg vote_independent i.condition if copartisan_D==0 & strong_moderate == 1, rob
reg aff_pol i.condition if copartisan_D==0 & strong_moderate == 1, rob

**# App. M 
frame reset
use  "data_S1.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above
set scheme plotplain

qui reg vote_inparty i.D if copartisan_D==1, rob
qui margins D
mat A = r(table)

qui reg vote_inparty i.D if copartisan_D==0, rob
qui margins D
mat B = r(table)


qui reg vote_outparty i.D if copartisan_D==1, rob
qui margins D
mat C = r(table)

qui reg vote_outparty i.D if copartisan_D==0, rob
qui margins D
mat D = r(table)

qui reg vote_independent i.D if copartisan_D==1, rob
qui margins D
mat E = r(table)

qui reg vote_independent i.D if copartisan_D==0, rob
qui margins D
mat F = r(table)



mat P = 1,0,0,A[1,1],A[5,1],A[6,1]\		///
		2,0,.3,A[1,2],A[5,2],A[6,2]\	///
		1,0,.6,B[1,1],B[5,1],B[6,1]\	///
		2,0,.9,B[1,2],B[5,2],B[6,2]\	///
		1,1,0,C[1,1],C[5,1],C[6,1]\		///
		2,1,.3,C[1,2],C[5,2],C[6,2]\	///
		1,1,.6,D[1,1],D[5,1],D[6,1]\	///
		2,1,.9,D[1,2],D[5,2],D[6,2]\	///
		1,2,0,E[1,1],E[5,1],E[6,1]\		///
		2,2,.3,E[1,2],E[5,2],E[6,2]\	///
		1,2,.6,F[1,1],F[5,1],F[6,1]\	///
		2,2,.9,F[1,2],F[5,2],F[6,2]
		
		
frame create plot1
cwf plot1		
svmat P
rename P1 condition
rename P2 outcome
rename P3 Xpos
rename P4 b
rename P5 ll
rename P6 ul	


tw ///
	(bar b Xpos if condition == 1, mlab(b) mlabformat(%5.2fc) mlabposition(12) mlabcolor(black) mlabgap(2) ///
	barw(.15) col(black) fcol(white) by(outcome, title("") note("") legend(off) rows(1))) ///
	(bar b Xpos if condition == 2, mlab(b) mlabformat(%5.2fc) mlabposition(12) mlabcolor(black) mlabgap(2) ///
	barw(.15) col(gs12) fcol(gs12) by(outcome)) ///
	(rspike ll ul Xpos if condition == 1, lcolor(black)) ///
	(rspike ll ul Xpos if condition == 2, lcolor(black)) ///
	, xscale(range(0 1) lc(none)) ///
	xlab(0 `" "In-Party" "Control" "' .3 `" "In-Party" "Treatment" "' .6 `" "Out-Party" "Control" "' .9 `" "Out-Party" "Treatment"  "', notick nogrid labsize(vsmall)) ///
	yscale(range(0 1) lc(none)) ylab(0 .2 .4 .6 .8 1, notick nogrid) ytit("Vote Share") yline(.5) ///
	xtit("Treatment Status") ///
	plotregion(lcolor(black) lwidth(medium)) ///
	name(vote_share, replace)
	


graph display, ysize(4.5) xsize(10) scale(1.4)


**# App. N 
frame reset
use  "data_S1.dta", clear 						// Remember to update file directory ("INSERTPATH") in cd above
set scheme plotplain

* rescale DVs to 0-1
gen support_inparty = . 
replace support_inparty = (feelings_dems/10) if pid < 0
replace support_inparty = (feelings_reps/10) if pid > 0
gen support_outparty = . 
replace support_outparty = (feelings_dems/10) if pid > 0
replace support_outparty = (feelings_reps/10) if pid < 0
gen aff_pol = (affective_polarization+10)/20

frame rename default data

* In-party affect
qui reg support_inparty i.D if copartisan_D==1 & pid < 0, rob			// Democrats
mat list r(table)
mat B1 = r(table)
qui reg support_inparty i.D if copartisan_D==1 & pid > 0, rob
mat list r(table)
mat B2 = r(table)
qui reg support_inparty i.D if copartisan_D==0 & pid < 0, rob			// Republicans
mat list r(table)
mat B3 = r(table)
qui reg support_inparty i.D if copartisan_D==0 & pid > 0, rob
mat list r(table)
mat B4 = r(table)

* Out-Party affect
qui reg support_outparty i.D if copartisan_D==1 & pid < 0, rob
mat list r(table)
mat C1 = r(table)
qui reg support_outparty i.D if copartisan_D==1 & pid > 0, rob
mat list r(table)
mat C2 = r(table)
qui reg support_outparty i.D if copartisan_D==0 & pid < 0, rob
mat list r(table)
mat C3 = r(table)
qui reg support_outparty i.D if copartisan_D==0 & pid > 0, rob
mat list r(table)
mat C4 = r(table)

* Affective polarization
qui reg aff_pol i.D if copartisan_D==1 & pid < 0, rob
mat list r(table)
mat D1 = r(table)
qui reg aff_pol i.D if copartisan_D==1 & pid > 0, rob
mat list r(table)
mat D2 = r(table)
qui reg aff_pol i.D if copartisan_D==0 & pid < 0, rob
mat list r(table)
mat D3 = r(table)
qui reg aff_pol i.D if copartisan_D==0 & pid > 0, rob
mat list r(table)
mat D4 = r(table)




mat H = 1,.81,B1[1,2],B1[5,2],B1[6,2],0\ 	///
		2,.79,B2[1,2],B2[5,2],B2[6,2],1\	///
		3,.76,C1[1,2],C1[5,2],C1[6,2],0\ 	///
		4,.74,C2[1,2],C2[5,2],C2[6,2],1\ 	///
		5,.71,D1[1,2],D1[5,2],D1[6,2],0\ 	///
		6,.69,D2[1,2],D2[5,2],D2[6,2],1
		

* make Panel A: 
frame create plot1
cwf plot1		
svmat H
rename H1 outcome
rename H2 Ypos
rename H3 b
rename H4 ll
rename H5 ul
rename H6 pid	

tw ///
	(rspike ll ul Ypos if pid == 0, horizontal lcolor("10 117 173")) ///
	(rspike ll ul Ypos if pid == 1, horizontal lcolor("255 64 64")) ///
	(scatter Ypos b if pid == 0, msym(O) mc("10 117 173") msize(med)) ///
	(scatter Ypos b if pid == 1, msym(O) mc("255 64 64") msize(med)) ///
	, yscale(range(.69 .85) lc(none)) ytit("") ///
	ylab(.83 "{bf:Party Attachments}" .8 "In-Party Affect" .75 "Out-Party Affect" .7 "Affective Polarization", notick nogrid) ///
	xtit("Treatment Effect") xscale(range(-.5 .25) lc(none)) xlab(-.4 -.2 0 .2, notick nogrid) xline(0) ///
	legend(off) plotregion(lcolor(black) lwidth(medium)) ///
	title("{bf:A} In-Party Cheating", size(medsmall) justification(left) pos(11)) ///
	name(S1_affect_pid_A, replace)

* Panel B:
mat I = 12,.81,B3[1,2],B3[5,2],B3[6,2],0\ 	///
		11,.79,B4[1,2],B4[5,2],B4[6,2],1\	///
		10,.76,C3[1,2],C3[5,2],C3[6,2],0\ 	///
		9,.74,C4[1,2],C4[5,2],C4[6,2],1\ 	///
		8,.71,D3[1,2],D3[5,2],D3[6,2],0\ 	///
		7,.69,D4[1,2],D4[5,2],D4[6,2],1

	

frame create plot2
cwf plot2		
svmat I
rename I1 outcome
rename I2 Ypos
rename I3 b
rename I4 ll
rename I5 ul
rename I6 pid		

tw ///
	(rspike ll ul Ypos if pid == 0, horizontal lcolor("10 117 173")) ///
	(rspike ll ul Ypos if pid == 1, horizontal lcolor("255 64 64")) ///
	(scatter Ypos b if pid == 0, msym(O) mc("10 117 173") msize(med)) ///
	(scatter Ypos b if pid == 1, msym(O) mc("255 64 64") msize(med)) ///
	, yscale(range(.69 .85) lc(none)) ytit("") ///
	ylab(none, notick nogrid) ///
	xtit("Treatment Effect") xscale(range(-.5 .25) lc(none)) xlab(-.4 -.2 0 .2, notick nogrid) xline(0) ///
	plotregion(lcolor(black) lwidth(medium)) ///
	title("{bf:B} Out-Party Cheating", size(medsmall) justification(left) pos(11)) ///
	legend(label(3 "Democrats") label(4 "Republicans") order(3 4) row(2) pos(4)) ///
	aspect(.55,place(w)) ///
	name(S1_affect_pid_B, replace)
		

graph combine S1_affect_pid_A S1_affect_pid_B, rows(1) ycommon 
graph display, xsize(8) ysize(2.5) scale(2.5)


